`include "macro.v"
module NPC (
    input wire [3:0] npc_sel_i,
    input wire eq_i,
    input wire lt_i,
    input wire ltu_i,
    input wire [31:0] pc_i,
    input wire [31:0] alu_c_i,
    input wire [31:0] ext_i,
    output reg pc_op_o,
    output reg [31:0] npc_o
);

// pc_op
always @(*) begin
    case (npc_sel_i)
        `NPC_NOP  : pc_op_o = `PC_PC4;
        `NPC_BEQ  : pc_op_o = ((eq_i == 1) ? `PC_NPC : `PC_PC4);
        `NPC_BNE  : pc_op_o = ((eq_i == 0) ? `PC_NPC : `PC_PC4);
        `NPC_BLT  : pc_op_o = ((lt_i == 1) ? `PC_NPC : `PC_PC4);
        `NPC_BGE  : pc_op_o = ((lt_i == 0) ? `PC_NPC : `PC_PC4);
        `NPC_BLTU : pc_op_o = ((ltu_i == 1) ? `PC_NPC : `PC_PC4);
        `NPC_BGEU : pc_op_o = ((ltu_i == 0) ? `PC_NPC : `PC_PC4);
        `NPC_JAL  : pc_op_o = `PC_NPC;
        `NPC_JALR : pc_op_o = `PC_NPC;
        default   : pc_op_o = `PC_PC4;
    endcase
end

// npc
always @(*) begin
    case (npc_sel_i)
        `NPC_NOP  : npc_o = 32'b0;
        `NPC_BEQ  : npc_o = pc_i + ext_i;
        `NPC_BNE  : npc_o = pc_i + ext_i;
        `NPC_BLT  : npc_o = pc_i + ext_i;
        `NPC_BGE  : npc_o = pc_i + ext_i;
        `NPC_BLTU : npc_o = pc_i + ext_i;
        `NPC_BGEU : npc_o = pc_i + ext_i;
        `NPC_JAL  : npc_o = pc_i + ext_i;
        `NPC_JALR : npc_o = alu_c_i;
        default   : npc_o = 32'b0;
    endcase
end

endmodule